﻿//由小小提供
(function show_meteor($, document, random) {
	'use strict';
	var num, mtop, mright, maxtmp, tmp, css, prop, animation, meteors;
	if (document.getElementById('meteors')) return;
	//opinions
	num = 10;
	mtop = -30 + 'px';
	mright = -75 + 'px';
	//maxtmp = 550;
	//tmp = random() * 100;
	var maxright=500,
	maxtop=800,
	max=maxright+maxtop;
	//opinions end
	css = function (node) {
		/*var style = node.style;
		if ((tmp += random() * 100 >> 0) > maxtmp) tmp = 0;
		random() > 0.5 ? (style.top = mtop, style.right = tmp-75 + 'px') : (style.top = tmp-30 + 'px', style.right = mright);
		style[animation] = 'meteor' + ((node.go = !node.go) ? 1 : 0) + ' 2.' + (random() * 1000 >> 0) + 's ease-out .' + (random() * 1000 >> 0) + 's';
		var otmp= random() * 10 >> 0
		style.opacity=otmp/10;*/
		var style = node.style;
		tmp=(random() * max >> 0)-maxtop;
		tmp <0 ? (style.top = mtop, style.right = -tmp-75 + 'px') : (style.top = tmp-30 + 'px', style.right = mright);
		style[animation] = 'meteor' + ((node.go = !node.go) ? 1 : 0) + ' 2.' + (random() * 1000 >> 0) + 's ease-out ' + (random() * 1900 >> 0)/1000 + 's';
		style.opacity=(random() * 10 >> 0)/10;
	};
	prop = (function getPrefix() {
		for (var prefixes = ['webkit', 'moz', 'ms', 'o'], i = prefixes.length - 1; i > -1; --i) if ((prefixes[i] + 'Hidden') in document) return prefixes[i];
	}()) || '';
	animation = ($.style(meteors = $('<div id="meteors" unselectable="on"></div>').css({
		'pointer-events': 'none',
		'user-select': 'none',
	}).get(0), 'animation'), $.cssProps.animation);
	meteors.innerHTML = (function () {
		var r, l, t = '<span class="meteor"></span>', res = '';
		'1' === (r = num.toString(2)).charAt(l = r.length - 1) && (res += t);
		while (l--) t += t, '1' === r.charAt(l) && (res += t);
		return res;
	}());
	[].forEach.call(meteors.children, css);
	document.addEventListener(prop + 'visibilitychange', function () {
		meteors.setAttribute('paused', document[prop]);
	});
	meteors.addEventListener(('moz' === prop || '' === prop) ? 'animationend' : prop + 'AnimationEnd', function (e) {
		css(e.target);
	});
	meteors.setAttribute('paused', document[prop += '' === prop ? 'hidden' : 'Hidden']);
	document.documentElement.appendChild(meteors);
}($, document, Math.random));